package com.wing.product.controller;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.common.annotation.RequestObjectFieldIgnore;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.product.model.entity.WarehouseSignOrder;
import com.wing.product.model.request.WarehouseSignOrderForm;
import com.wing.product.model.response.WarehouseOutboundOrderVO;
import com.wing.product.model.response.WarehouseSignOrderVO;
import com.wing.product.service.WarehouseSignOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 托管订单（签收）(warehouse_sign_order)表控制层
*
* @author xxxxx
*/
@Api(value = "托管入库管理(签收)", tags = "#/warehouse/product/signOrder")
@RestController("WarehouseSignOrderController")
@RequestMapping("/warehouse/signOrder")
@RequiredArgsConstructor
public class WarehouseSignOrderController {
/**
* 服务对象
*/
    @Autowired
    private WarehouseSignOrderService warehouseSignOrderService;


    @ApiOperation(value = "查询列表", notes = "搜索")
    @GetMapping("/list")
    public PageResult<WarehouseSignOrderVO> list(
            @RequestParam(value = "page", defaultValue = "1", required = false) Integer page
            ,@RequestParam(value = "limit", defaultValue = "10", required = false) Integer limit
            ,@RequestParam(value = "sort", defaultValue = "create_time", required = false) String sort
            ,@RequestParam(value = "order", defaultValue = "asc", required = false) String order
            ,Integer status,
            String customerName,
            String customerId,
            String signOrder
    ){

        Page<WarehouseSignOrder> pg = new Page<>(page, limit);
        Map paramMap=new HashMap();
        paramMap.put("status",status);
        paramMap.put("customerName",customerName);
        paramMap.put("customerId",customerId);
        paramMap.put("signOrder",signOrder);
        //搜索
//        return warehouseSignOrderService.pageList4app(pg,paramMap);
        IPage<WarehouseSignOrderVO> list = warehouseSignOrderService.pageList4app(pg,paramMap);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

    @ApiOperation(value = "添加签收订单", notes = "添加")
    @RequestObjectFieldIgnore({"id", "createTime", "remark"})
    @PostMapping("/add")
    public JsonResult add(@Validated(WarehouseSignOrderForm.Add.class)  @RequestBody WarehouseSignOrderForm warehouseSignOrderForm)  {
        try{

            Boolean b =  warehouseSignOrderService.save(warehouseSignOrderForm);
            if(b){
                return JsonResult.success("添加成功");
            } else {
                return JsonResult.fail("添加失败");
            }
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.fail(e.getMessage());
        }
    }

    @ApiOperation(value = "看板物流签收", notes = "搜索")
    @GetMapping ("/selectLogistics")
    public JsonResult<Map<String,Object>> selectLogistics(){
        return  warehouseSignOrderService.selectLogistics();
    }



    @ApiOperation(value = "添加时候的详情", notes = "详情")
    @GetMapping("/addInfo")
    public JsonResult addInfo(String waybill) {
        return JsonResult.success(warehouseSignOrderService.addInfo(waybill));
    }

    @ApiOperation(value = "详情", notes = "详情")
    @GetMapping("/Info")
    public JsonResult Info(Long id ) {
        return JsonResult.success(warehouseSignOrderService.info(id));
    }

    @ApiOperation(value = "单个签收", notes = "单个签收")
    @GetMapping("/signSingle")
    public JsonResult signSingle(Long id ,String remarks, Long signQualified,Long areaId,Long spaceId,Long unqualifiedId,String unqualifiedReason) {
        return JsonResult.success(warehouseSignOrderService.signSingle(id,remarks,signQualified,areaId,spaceId,unqualifiedId,unqualifiedReason));
    }
}
